package com.xintoucloud.pbs.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.pbs.dao.OrganizationStageDao;
import com.xintoucloud.pbs.entity.OrganizationStage;
@Repository@Transactional
public class OrganizationStageDaoImpl implements OrganizationStageDao {
	
	@Autowired
	private SessionFactory sessionFactory;

	@SuppressWarnings("unchecked")
	@Override
	public List<OrganizationStage> list() {
		
		return sessionFactory.getCurrentSession().createQuery("from OrganizationStage").list();
	}

	@Override
	public OrganizationStage getOne(int id) {
		return sessionFactory.getCurrentSession().get(OrganizationStage.class, id);
	}
	
	@Override
	public void delete(int id) {
		sessionFactory.getCurrentSession().delete(getOne(id));
	}

	@Override
	public void update(OrganizationStage organizationStage) {
		int osgid = organizationStage.getOsgid();
		String ostage = organizationStage.getOstage();
		String detail = organizationStage.getDetail();
		sessionFactory.getCurrentSession().createQuery("update OrganizationStage o set o.ostage='"+ostage+"',o.detail='"+detail+"' where o.osgid="+osgid+" ").executeUpdate();
		/*sessionFactory.getCurrentSession().createQuery("update OrganizationStage o set o.ostage =?0, o.describe=?1 where osgid=?2 ")
		.setParameter(0,ostage)
		.setParameter(1,describe)
		.setParameter(2, osgid)
		.executeUpdate();*/
	}
}
